import Vue from 'vue'
import VueRouter from 'vue-router'
import LoginView from '../views/LoginView.vue'
import IndexView from "../views/IndexView.vue" 
import Main from "../views/Main.vue"
Vue.use(VueRouter)
const routes = [
	{
		path:"/",
		redirect:'/login'
	},
	{
		path: '/login',
		name: 'login',
		component: LoginView
	},
	{
		path: '/index',
		name: 'index',
		component: IndexView,
		redirect:'/index/main',
		meta:{
		auth:true
		},
		children:[
		{
			path:"/index/main",
			component:Main,
			name:'main'
		},
		{
			path:"/index/information",
			component:()=>import('../views/Information.vue'),
			name:'information'
		},
		{
			path:"/index/newbuilding",
			component:()=>import('../views/NewBuilding.vue'),
			name:'newbuilding'
		},
		{
			path:'/index/room',
			component:()=>import('../views/Room.vue'),
			name:'room'
		},
		{
			path:"/index/storage",
			component:()=>import('../views/Storage.vue'),
			name:"storage"
		},
		{
			path:"/index/Lease",
			component:()=>import('../views/Lease.vue'),
			name:"lease"
		},
		{
			path:"/index/region",
			component:()=>import('../views/Region.vue'),
			name:"region"
		},
		{
			path:"/index/pay",
			component:()=>import('../views/Pay.vue'),
			name:"pay"
		},
		{
			path:"/index/lot",
			component:()=>import('../views/Lot.vue'),
			name:"lot"
		},
		{
			path:"/index/vehicle",
			component:()=>import('../views/Vehicle.vue'),
			name:"vehicle"
		},
		{
			path:"/index/card",
			component:()=>import('../views/Card.vue'),
			name:"card"
		},
		{
			path:"/index/visitor",
			component:()=>import('../views/Visitor.vue'),
			name:"visitor"
		},
		{
			path:"/index/complaint",
			component:()=>import('../views/Complaint.vue'),
			name:"complaint"
		},
		{
			path:"/index/activity",
			component:()=>import('../views/Activity.vue'),
			name:"activity"
		},
		{
			path:"/index/notice",
			component:()=>import('../views/Notice.vue'),
			name:"notice"
		},
		{
			path:"/index/charge",
			component:()=>import('../views/Charge.vue'),
			name:"charge"
		},
		{
			path:"/index/cycle",
			component:()=>import('../views/Cycle.vue'),
			name:"cycle"
		},
		{
			path:"/index/public",
			component:()=>import('../views/Public.vue'),
			name:"public"
		},
		{
			path:"/index/classification",
			component:()=>import('../views/Classification.vue'),
			name:"classification"
		},
		{
			path:"/index/maintenance",
			component:()=>import('../views/Maintenance.vue'),
			name:"maintenance"
		},
		{
			path:"/index/record",
			component:()=>import('../views/Record.vue'),
			name:"record"
		},
		{
			path:"/index/mission",
			component:()=>import('../views/Mission.vue'),
			name:"mission"
		},
		{
			path:'/index/plan',
			component:()=>import('../views/Plan.vue'),
			name:"plan"
		},
		{
			path:"/index/points",
			component:()=>import('../views/Points.vue'),
			name:"points"
		},
		{
			path:"/index/routes",
			component:()=>import('../views/Routes.vue'),
			name:"routes"
		},
		{
			path:"/index/project",
			component:()=>import('../views/Project.vue'),
			name:"project"
		},
		{
			path:"/index/daily",
			component:()=>import('../views/Daily.vue'),
			name:"daily"
		},
		{
			path:"/index/weekly",
			component:()=>import('../views/Weekly.vue'),
			name:"weekly"
		},
		{
			path:"/index/monthly",
			component:()=>import('../views/Monthly.vue'),
			name:"monthly"
		},
		{
			path:"/index/business",
			component:()=>import('../views/Business.vue'),
			name:"business"
		},
		{
			path:"/index/resident",
			component:()=>import('../views/Resident.vue'),
			name:"resident"
		},
		{
			path:'/index/complain',
			component:()=>import('../views/Complain.vue'),
			name:"complain"
		},
		{
			path:"/index/facilities",
			component:()=>import('../views/Facilities.vue'),
			name:"facilities"
		},
		{
			path:"/index/staff",
			component:()=>import('../views/Staff.vue'),
			name:"staff"
		},
		{
			path:"/index/role",
			component:()=>import('../views/Role.vue'),
			name:"role"
		},
		{
			path:"/index/log",
			component:()=>import('../views/Log.vue'),
			name:"log"
		},
		{
			path:"/index/newroom",
			component:()=>import('../views/NewRoom.vue'),
			name:"newroom"
		},
		{
			path:"/index/newstorage",
			component:()=>import('../views/NewStorage.vue'),
			name:"newstorage"
		},
		{
			path:'/index/newregion',
			component:()=>import('../views/NewRegion.vue'),
			name:"newregion"
		},
		{
			path:"/index/newlot",
			component:()=>import('../views/NewLot.vue'),
			name:"newlot"
		},
		{
			path:"/index/newcard",
			component:()=>import('../views/NewCard.vue'),
			name:"newcard"
		},
		{
			path:'/index/household',
			component:()=>import('../views/Household.vue'),
			name:"household"
		},
		{
			path:"/index/roomdetail",
			component:()=>import('../views/RoomDetail.vue'),
			name:"roomdetail"
		}
		]
	}
]
const router = new VueRouter({
	mode: 'history',
	routes
})

router.beforeEach((to,from,next)=> {
	if(to.matched.some(item=> item.meta.auth==true)){
		if(localStorage.getItem("logins")) {
			next()
		}else {
			console.log(to,from)
			next('/')
		}
	}else {
		next()
	}
})
export default router
